package conf

import (
	"encoding/json"
	"errors"
	"io/ioutil"
	"time"
)

type RedisConfig struct {
	Network      string        `json:"network"`
	Addr         string        `json:"addr"`
	Password     string        `json:"password"`
	Db           int           `json:"db"`
	DialTimeout  time.Duration `json:"dial_timeout"`
	ReadTimeout  time.Duration `json:"read_timeout"`
	WriteTimeout time.Duration `json:"write_timeout"`
}

func NewConfig(path string) (*RedisConfig, error) {
	configByte, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, err
	}
	if len(configByte) <= 0 {
		return nil, errors.New("log config file invalid")
	}

	var cif RedisConfig
	err = json.Unmarshal(configByte, &cif)
	return &cif, err
}
